Accord Software, Inc.

tutorial05/tree.c




/* 
 * Accord Software, Inc.             1
 *                                 /  \
 * Tutorial 05 - CIDL file.       /    \
 *                               /      \
 * Tree struct                  /        \
 *                             /          \
 *                            /            \ 
 *                           2              9
 *                         /  \            /  \
 *                        /    \          /    \
 *                       3      6       10      13
 *                     /  \    /  \    /  \    /  \
 *                    4    5  7    8  11  12  14  15
 */

#include "tree.h"

int
tsum(tp)
	struct tnode *tp;
{
	int sum = 0;

	if (tp) {
		printf("%d\n", tp->num);
		sum += tp->num;
		sum += tsum(tp->left);
		sum += tsum(tp->right);
	}
	return sum;
}

int
tokenprint(sp)
	struct strnode *sp;
{
	if (sp) {
		if (sp->token)
			printf("%s\n", sp->token);
		tokenprint(sp->left);
		tokenprint(sp->right);
	}
	return 0;
}

[ Home | Tutorials | main.c | tree.h ]
E-Mail:webmaster@accord.com
[P-046] Updated March 14, 1996
Copyright © 1993-1996 Accord Software, Inc. All rights reserved.